package com.elite.service;

import com.elite.dao.ShoppingCartMapper;
import com.elite.entity.ShoppingCart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/2/17.
 */
@Service("ShoppingCartService")
public class ShoppingCartServiceImp implements ShoppingCartService {

    @Autowired
    private ShoppingCartMapper shoppingCartMapper;

    @Override
    public void addShoppingCart(ShoppingCart shoppingCart) {
        shoppingCartMapper.insert(shoppingCart);
    }

    @Override
    public ShoppingCart selectByByUserIdAndGoodsId(Integer userId, Integer goodsId) {

        Map<String,Object> map = new HashMap<String, Object>();
        if (userId != null && goodsId != null){
            map.put("userId",userId);
            map.put("goodsId",goodsId);
        }

        return shoppingCartMapper.selectByByUserIdAndGoodsId(map);
    }

    @Override
    public ShoppingCart selectByPrimaryKey(Integer shoppingcartId) {
        return shoppingCartMapper.selectByPrimaryKey(shoppingcartId);
    }

    @Override
    public void updateByPrimaryKey(ShoppingCart shoppingCart) {
        shoppingCartMapper.updateByPrimaryKey(shoppingCart);
    }

    @Override
    public List selectByUserId(Integer userId) {
        return shoppingCartMapper.selectByUserId(userId);
    }

    @Override
    public void deleteShoppingCart(Integer shoppingcartId) {
        shoppingCartMapper.deleteByPrimaryKey(shoppingcartId);
    }
}
